package com.hitgo.soccer.config;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class MatchConfig
{
	public static int maxRound = 180;
	
	public static int playerPauseInterval = 50;
	
	
	public static int fieldWidth = 200;
	public static int fieldHeight = 120;
	
	public static int goalWidth = 100;
	
	// 球门的上下点
	public static int goalTopY = (fieldWidth - goalWidth )/2;
	public static int goalDownY = (fieldWidth + goalWidth )/2;
	
	// 开球时的初始位置，
	public static int ballInitX = fieldWidth / 2;
	public static int ballInitY = fieldHeight / 2;

	public static void loadConfig(String strFile)
	{
		if (strFile == null || strFile.isEmpty())
			return;
			
		// 获取文档的根元素，赋值给rootElement变量
		Element rootElement = ConfigUtil.GetRootElement(strFile);
		if(rootElement == null)
			return ;
		
		Node nodeField = rootElement.getElementsByTagName("field").item(0);

		fieldWidth = ConfigUtil.GetAttributeIntValue(nodeField, "width");
		fieldHeight = ConfigUtil.GetAttributeIntValue(nodeField, "height");
		goalWidth = ConfigUtil.GetAttributeIntValue(nodeField, "goal_width");
		
		goalTopY = (fieldHeight - goalWidth )/2;
		goalDownY = (fieldHeight + goalWidth )/2;
		ballInitX = fieldWidth / 2;
		ballInitY = fieldHeight / 2;
		
		Node nodeMatch = rootElement.getElementsByTagName("match").item(0);
		maxRound = ConfigUtil.GetAttributeIntValue(nodeMatch, "round");
		playerPauseInterval = ConfigUtil.GetAttributeIntValue(nodeMatch, "player_pause");
	}
}
